<template>
  <div class="d2-layout-header-aside-group" :style="styleLayoutMainGroup" :class="{ grayMode: grayActive }">
    <!-- 半透明遮罩 -->
    <div class="d2-layout-header-aside-mask"></div>
    <!-- 主体内容 -->
    <div class="d2-layout-header-aside-content" flex="dir:top">
      <!-- 顶栏 -->
      <div class="d2-theme-header" :style="{ opacity: this.searchActive ? 0.5 : 1 }" flex-box="0" flex style="background-color: #ffffff;">
        <div class="logo-group" :style="{ width: asideCollapse ? asideWidthCollapse : asideWidth }" flex-box="0">
          <img v-if="asideCollapse" :src="`${$baseUrl}image/theme/${themeActiveSetting.name}/logo/icon-only.png`">
          <img class="fristImg" v-else :src="`${$baseUrl}image/theme/${themeActiveSetting.name}/logo/all.png`">
          <div class="selectHotel" v-show="!asideCollapse" style="line-height: 60px;">
            <el-popover placement="bottom" title="" width="180" trigger="click">
              <div>
                <div style="color: #0486FE;line-height: 36px;">
                  <i class="el-icon-s-home" style="font-size: 21px;"> </i> 门店
                </div>
                <div class="HotelItem" :class="item.id == nowHotel_id ? 'hotel_item' : ''" v-for="item in  hotel "
                  :key="item.id" @click="selectHotel(item)">
                  {{ item.name }}
                </div>
                <div class="toAdd" @click="toAdd">
                  创建门店<i class="el-icon-arrow-right" style="line-height: 36px;"></i>
                </div>
              </div>
              <div slot="reference" class="hotel_show">
                <div class="hotel_name">{{ nowHotel.name }} </div>
                <span> <i class="el-icon-arrow-up"></i></span>
              </div>
            </el-popover>
          </div>
        </div>
        <div class="toggle-aside-btn" @click="handleToggleAside" flex-box="0">
          <d2-icon name="bars" />
        </div>
        <d2-menu-header flex-box="1" />
        <!-- 顶栏右侧 -->
        <div class="d2-header-right" flex-box="0">
          <!-- 如果你只想在开发环境显示这个按钮请添加 v-if="$env === 'development'" -->
          <warning @warning="warning" />
          <wallet-header @WalletClick="WalletClick" />
          <messag-logginge-header></messag-logginge-header>
          <d2-header-search @click="handleSearchClick" />
          <d2-header-log />
          <d2-header-fullscreen />
          <d2-header-theme />
          <d2-header-size />
          <d2-header-user />
        </div>
      </div>
      <!-- 下面 主体 -->
      <div class="d2-theme-container" flex-box="1" flex>
        <!-- 主体 侧边栏 -->
        <!-- 不用时，暂时关闭 -->
        <!-- <div
          flex-box="0"
          ref="aside"
          class="d2-theme-container-aside"
          :style="{
            width: asideCollapse ? asideWidthCollapse : asideWidth,
            opacity: this.searchActive ? 0.5 : 1
          }">
          <d2-menu-side/>
        </div> -->
        <!-- 主体 -->
        <div class="d2-theme-container-main" flex-box="1" flex>
          <!-- 搜索 -->
          <transition name="fade-scale">
            <div v-if="searchActive" class="d2-theme-container-main-layer" flex>
              <d2-panel-search ref="panelSearch" @close="searchPanelClose" />
            </div>
          </transition>
          <!-- 内容 -->
          <transition name="fade-scale">
            <div v-if="!searchActive" class="d2-theme-container-main-layer" flex="dir:top">
              <!-- tab 标签页-->
              <!-- <div class="d2-theme-container-main-header" flex-box="0" >
                <d2-tabs />
              </div> -->
              <!-- 页面 -->
              <div class="d2-theme-container-main-body" flex-box="1">
                <transition :name="transitionActive ? 'fade-transverse' : ''">
                  <keep-alive :include="keepAlive">
                    <router-view />
                  </keep-alive>
                </transition>
              </div>
            </div>
          </transition>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import d2MenuSide from './components/menu-side'
import d2MenuHeader from './components/menu-header'
import d2Tabs from './components/tabs'
import d2HeaderFullscreen from './components/header-fullscreen'
import d2HeaderSearch from './components/header-search'
import d2HeaderSize from './components/header-size'
import d2HeaderTheme from './components/header-theme'
import d2HeaderUser from './components/header-user'
import d2HeaderLog from './components/header-log'
import walletHeader from './components/header-wallet'
import messagLoggingeHeader from './components/header-message-logging'
import warning from './components/header-warning'
import { mapState, mapGetters, mapActions } from 'vuex'
import mixinSearch from './mixins/search'
import { GetHotel } from '@/api/basis.js'

export default {
  name: 'd2-layout-header-aside',
  mixins: [
    mixinSearch
  ],
  components: {
    // d2MenuSide,
    d2MenuHeader,
    // d2Tabs,
    d2HeaderFullscreen,
    d2HeaderSearch,
    d2HeaderSize,
    d2HeaderTheme,
    d2HeaderUser,
    d2HeaderLog,
    walletHeader,
    messagLoggingeHeader,
    warning,
  },
  data() {
    return {
      drawer: false,
      // [侧边栏宽度] 正常状态
      asideWidth: '200px',
      // [侧边栏宽度] 折叠状态
      asideWidthCollapse: '65px',
      hotel: null,
      nowHotel_id: sessionStorage.getItem('hotel_id'),
      nowHotel: {}
    }
  },
  computed: {
    ...mapState('d2admin', {
      keepAlive: state => state.page.keepAlive,
      grayActive: state => state.gray.active,
      transitionActive: state => state.transition.active,
      asideCollapse: state => state.menu.asideCollapse
    }),
    ...mapGetters('d2admin', {
      themeActiveSetting: 'theme/activeSetting'
    }),
    /**
     * @description 最外层容器的背景图片样式
     */
    styleLayoutMainGroup() {
      return {
        ...this.themeActiveSetting.backgroundImage ? {
          backgroundImage: `url('${this.$baseUrl}${this.themeActiveSetting.backgroundImage}')`
        } : {}
      }
    }
  },
  created() {
    this.getHotel()
  },
  methods: {
    WarningData() {
      console.log('父组件');
    },
    WalletClick() {
      this.$router.push({ path: '/Wallet' })
      console.log("父组件钱包");
    },
    warning() {
      this.drawer = true
      console.log("图例说明");
    },
    ...mapActions('d2admin/menu', [
      'asideCollapseToggle'
    ]),

    async getHotel() {
      await GetHotel().then(res => {
        this.hotel = res.data.data
        // console.log(this.hotel, 'hotel');
        this.hotel.forEach(element => {
          if (element.id == this.nowHotel_id) {
            this.nowHotel = element
          }
        });
      })
    },
    selectHotel(item) {
      // console.log(item);
      sessionStorage.setItem('hotel_id', item.id)
      sessionStorage.setItem('hotel_name', item.name)
      this.$store.dispatch("d2admin/hotel/saveHotel_id", { hotel_id: item.id }, { root: true });
      // this.$router.push('/RoomStatus')
      this.$router.go(0)
    },
    /**
     * 跳转到创建门店，
     */
    toAdd() {
      this.$router.push({ path: '/AddSystem' })
    },
    /**
     * 接收点击切换侧边栏的按钮
     */
    handleToggleAside() {
      this.asideCollapseToggle()
    }
  }
}

</script>

<style lang="scss" >
// 注册主题
@import "~@/assets/style/theme/register.scss";

.logo-group {
  display: flex !important;

  .fristImg {
    margin-left: 15px;
  }

}

.selectHotel {
  position: absolute;
  left: 90px;
  width: 120px;

  .hotel_show {
    display: flex;

    .hotel_name {
      width: 90px;
      white-space: nowrap; //防止文本换行
      overflow: hidden; //控制溢出隐藏
      text-overflow: ellipsis; //显示省略号
    }
  }

}

.toAdd {
  margin-top: 5px;
  border-top: 1px solid #ccc;
  line-height: 36px;
  height: 27px;
  color: #51A6FB;
  display: flex;
  justify-content: space-between;
}

.HotelItem {
  height: 36px;
  line-height: 36px;
}

.hotel_item {
  background-color: #E6ECFA;
  color: #51A6FB;
}
</style>
